package com.zsy.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zsy.service.BBSService;

public class PrefixConf extends HttpServlet {
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			request.setCharacterEncoding("UTF-8");
			String site = request.getParameter("site"); // 网站信息
			String prefix = request.getParameter("prefix"); // 前缀信息
			String bbsRegex = request.getParameter("bbsRegex"); // 判断抓取的url是否符合bbs的标准
			String encode = request.getParameter("encode"); // 网站的编码方式
			String structRegex = request.getParameter("structRegex");// 判断页面是否是结构化界面的正则表达式
			String beginUrl = request.getParameter("beginUrl");// 开始url
//			String host = request.getParameter("host"); // host主机信息
//			if(!host.endsWith("/")){
//				host = host+"/";
//			}
			String filename = request.getParameter("filename"); // 配置cookie信息， 某些网站需要配置cookie
			String isBBS = request.getParameter("type"); // 是否是bbs
			String urlPrefixRegex = request.getParameter("urlPrefix_regex");
			BBSService bbss = new BBSService();
//			bbss.savePrefixConf(site, prefix, bbsRegex, encode, structRegex, beginUrl, host, cookie, isBBS);
			bbss.savePrefixConf(site, prefix, bbsRegex, encode, structRegex, beginUrl, filename, isBBS,urlPrefixRegex);
			request.getSession().setAttribute("msg","添加操作成功！");
			response.sendRedirect(request.getContextPath()+"/allPrefixConf");
		} catch (SQLException e) {
			response.sendRedirect(request.getContextPath()+"/allPrefixConf");
			e.printStackTrace();
		}
	}
}
